/** 
  *@CopyRight(c)2009 company Co.Ltd. 
  *@All right reserved.
  *@module name: App.Base.SystemManage.SystemUsersMgrWindow
  *@description:
  *
  *@author: lugj
  *@version: 1.0
  *@date: 2009/07/18
  *@last date: 2009/07/18
  *@history:
    1.
    2.
  *@bugs:
    1. 
    2. 
  *
*/ 

Ext.namespace("App.Base.SystemManage");

//SystemUsersMgrWindow Class
App.Base.SystemManage.SystemUsersMgrWindow = function(config){
	this.config = config;
	this.MODULE_ID = App.Base.Common.func.generateGlobalUniqueId(this.config, 'SYSUSERMGRWIN');

    this.setHandler = function(handler, scope){
        this.handler = handler;
        this.scope = scope;
    };
	this.setHandler(this.config.handler, this.config.scope);

	this.action = App.Base.common.param.BUTTON_ACTION_NONE;

	this.form = new Ext.form.FormPanel({
		border: false,
		autoScroll: true,
		frame: true,
		defaults: {width: 360},
		defaultType: 'textfield',
		labelAlign: 'top',
		labelWidth: 128,
		bodyStyle:'padding:10px 5px 5px 10px',
		layout: 'form',
		items :[{
			xtype: 'fieldset',
			title: '系统用户基础信息',
			collapsible: true,
			collapsed: false,
			autoHeight: true,
			labelAlign: 'top',
			labelWidth: 128,
			layout: 'form',
			items: [{
				xtype: 'textfield',
				id: 'loginId' + this.MODULE_ID,
				name: 'loginId' + this.MODULE_ID,
				width: 336,
				fieldLabel: '<font color="red">登录账号 (必填)</font>',
				maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
				regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
				regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS,
				allowBlank: false
			},{
				xtype: 'textfield',
				id: 'loginPwd' + this.MODULE_ID,
				name: 'loginPwd' + this.MODULE_ID,
				width: 336,
				fieldLabel: '<font color="red">密码 (必填)</font>',
				maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
				regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
				regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS,
				inputType: 'password',
				minLength: 6,
				minLengthText: '密码至少输入6位字符',
				allowBlank: false
			},{
				xtype: 'textfield',
				id: 'loginPwdConfirm' + this.MODULE_ID,
				name: 'loginPwdConfirm' + this.MODULE_ID,
				width: 336,
				fieldLabel: '<font color="red">密码确认 (必填)</font>',
				maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
				regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
				regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS,
				inputType: 'password',
				minLength: 6,
				minLengthText: '密码至少输入6位字符',
				allowBlank: false
			}, 
			new Ext.Button({
				id: 'btnSelectParentId' + this.MODULE_ID,
				text: '<font color="red">选择系统用户类型 (必选)</font>',
				handler: function(){
					new App.Base.SystemManage.SystemSelectTreeWindow({
						id: this.MODULE_ID,
						title: '选择系统用户类型',
						leaf: '0',
						asyncTreeNode: {
							id: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_ID,
							text: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_NORMAL_TITLE,
							icon: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_NORMALICON_URL,
							expandIcon: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_EXPANDICON_URL,
							qtip: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_QTIP,
							singleClickExpand: true
						},
						dataUrl: App.Base.common.param.SYSUSERTYPEMGR_ASYNC_TREELOADER_DATAURL,
						handler: function(o, node){
							if (o.action == App.Base.common.param.BUTTON_ACTION_OK)
							{
								var nodeId = node.id.substr(0, node.id.length - o.MODULE_ID.length);
								this.userTypeId = nodeId;
								Ext.getCmp('userTypeName' + this.MODULE_ID).setValue(node.text + App.Base.common.param.SPLIT_CHARS_UNDELINE + nodeId);
							}
						},
						scope: this
					}).getMainPanel().show();
				},
				scope: this
			}), {
				xtype: 'textfield',
				id: 'userTypeName' + this.MODULE_ID,
				name: 'userTypeName' + this.MODULE_ID,
				width: 336,
				fieldLabel: '<font color="red">系统用户类型(必填)</font>',
				readOnly: true,
				disabled: true,
				hideLabel: true,
				maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
				regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
				regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS,
				allowBlank: false,
				emptyText : '请选系统用户类型...'
			},{
				xtype: 'textfield',
				id: 'userName' + this.MODULE_ID,
				name: 'userName' + this.MODULE_ID,
				fieldLabel: '<font color="#FF0000">用户名称 (必填)</font>',
				width: 336,
				maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
				regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
				regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS,
				allowBlank: false
			}, {
				xtype: 'textfield',
				id: 'userDesc' + this.MODULE_ID,
				name: 'userDesc' + this.MODULE_ID,
				width: 336,
				fieldLabel: '<font color="red">用户描述</font>',
				maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
				regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
				regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS
			}]
		}, {
			xtype: 'fieldset',
			title: '其他选项',
			collapsible: true,
			//collapsed: true,
			autoHeight: true,
			labelAlign: 'top',
			labelWidth: 128,
			layout: 'form',
			items: [{
				xtype: 'textfield',
				id: 'displayRankingIndex' + this.MODULE_ID,
				name: 'displayRankingIndex' + this.MODULE_ID,
				value: '0',
				width: 336,
				fieldLabel: '<font color="red">显示顺序号 (必填 降序)</font>',
				regex: /^-?\d+$/,
				regexText:"只能够输入数字(最多16位)", 
				maxLength: 16, 
				allowBlank: false
			}, 
				new Ext.form.ComboBox({
				id: 'sysHoldFlag' + this.MODULE_ID,
				fieldLabel: '<font color="red">系统创建标志</font>',
				width : 60,
				store: new Ext.data.SimpleStore({
					fields: ['value', 'text'],
					data: [
						['0', '否'],
						['1', '是']
					]
				}),
				value: 0,	
				mode: 'local',
				editable: false,
				triggerAction: 'all',
				valueField: 'value',
				displayField: 'text'
			}), 
				new Ext.form.ComboBox({
				id: 'state' + this.MODULE_ID,
				fieldLabel: '<font color="red">状态</font>',
				width : 120,						
				store: new Ext.data.SimpleStore({
					fields: ['value', 'text'],
					data: [
						['0', '正常'],
						['1', '已冻结']
					]
				}),
				value: 0,	
				mode: 'local',
				editable: false,
				triggerAction: 'all',
				valueField: 'value',
				displayField: 'text'
			})
			]
		}]
	});

	this.init = function(){
		if (config.opCmd == App.Base.common.param.OP_CMD_MODIFY)
		{
			Ext.getCmp('loginId' + this.MODULE_ID).setValue(config.initValues.loginId);
			this.userTypeId = config.initValues.userTypeId;
			Ext.getCmp('userTypeName' + this.MODULE_ID).setValue(config.initValues.userTypeName + App.Base.common.param.SPLIT_CHARS_UNDELINE + config.initValues.userTypeId);
			Ext.getCmp('userName' + this.MODULE_ID).setValue(config.initValues.userName);
			Ext.getCmp('userDesc' + this.MODULE_ID).setValue(config.initValues.userDesc);
			Ext.getCmp('displayRankingIndex' + this.MODULE_ID).setValue(config.initValues.displayRankingIndex);
			Ext.getCmp('sysHoldFlag' + this.MODULE_ID).setValue(config.initValues.sysHoldFlag);
			Ext.getCmp('state' + this.MODULE_ID).setValue(config.initValues.state);
		}
	};
	this.init();

	this.win = new Ext.Window({
		//id: 'win' + this.MODULE_ID,
		title: this.config.title,
		iconCls: this.config.iconCls,
		width: 440,
		minWidth: 420,
		height: 512,
		minHeight: 360,
		plain: true,
		maximizable: true,
		collapsible: true,
		constrain: true,
		modal: true,
		layout: 'fit',
		items: [this.form],
		buttonAlign: 'right',
		buttons: [{
			text: '确 定',
			handler: function(){
				if (!this.form.getForm().isValid())
				{
					App.Base.Common.func.MESSAGEBOX_SHOW({
						title: App.Base.common.param.MESSAGEBOX_NORMAL_TIPS,
						msg: '填写的数据格式不正确',
						icon: Ext.MessageBox.ERROR
					});					
					return;
				}

				if (!(Ext.getCmp('loginPwdConfirm' + this.MODULE_ID).getValue() == Ext.getCmp('loginPwd' + this.MODULE_ID).getValue()))
				{
					App.Base.Common.func.MESSAGEBOX_SHOW({
						title: App.Base.common.param.MESSAGEBOX_NORMAL_TIPS,
						msg: '输入的2次密码不一致',
						icon: Ext.MessageBox.ERROR
					});					
					return;
				}

				if (Ext.getCmp('userTypeName' + this.MODULE_ID).getValue().trim().length == 0)
				{
					App.Base.Common.func.MESSAGEBOX_SHOW({
						title: App.Base.common.param.MESSAGEBOX_NORMAL_TIPS,
						msg: '用户类型不能为空',
						icon: Ext.MessageBox.ERROR
					});					
					return;
				}

				this.action = App.Base.common.param.BUTTON_ACTION_OK;
				this.win.close();
			},
			scope: this
		},{
			text: '取 消',
			handler: function(){
				this.action = App.Base.common.param.BUTTON_ACTION_CANCEL;
				this.win.close();
			},
			scope: this
		}],
		
		listeners: {
			beforeclose: function(o){
				if (!(this.action == App.Base.common.param.BUTTON_ACTION_OK))
				{
					this.action = App.Base.common.param.BUTTON_ACTION_NONE;
				}
				if (this.handler)
				{
					this.handler.call(this.scope || this, this);
				}
				return true;
			},
			scope: this
		}

	});

	//this.win.doLayout();

	//defined methods.
    if ((typeof App.Base.SystemManage.SystemUsersMgrWindow.SIMULATE_SHARED_METHODS_FLAG) == "undefined")
    {
        App.Base.SystemManage.SystemUsersMgrWindow.SIMULATE_SHARED_METHODS_FLAG = true;
		
        App.Base.SystemManage.SystemUsersMgrWindow.prototype.getMainPanel = function(){
            return this.win;  
        };
 
        var __ctor = function(){
        }();
    }
}